package ylsb.service;


import org.springframework.stereotype.Service;
import ylsb.dao.HaocaiyinjinMapper;
import ylsb.model.Haocaiyinjin;
import ylsb.model.HaocaiyinjinExample;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class HaocaiyinjinService {

    @Resource
    HaocaiyinjinMapper ddMapper;

    /*public List<Haocaiyinjin> findHaocaiyinjinlist(String xiangmuId){
        HaocaiyinjinExample mmExample=new HaocaiyinjinExample();
        mmExample.createCriteria().andXiangmuidEqualTo(xiangmuId);
        mmExample.setOrderByClause("ordernumber ASC");
        return  ddMapper.selectByExample(mmExample);
    }*/
    public List<Map<String, Object>> findPinzhongAll(String ppxiangmuId,int ppPageIndex, int ppPageSize){
        int mmStartIndex = (ppPageIndex - 1) * ppPageSize;
        return ddMapper.findPinzhongAll(ppxiangmuId,mmStartIndex,ppPageSize);
    }
    public List<Map<String, Object>> findDaochuPinzhongAll(String ppxiangmuId){
        return ddMapper.findDaochuPinzhongAll(ppxiangmuId);
    }
    public List<Map<String, Object>> findPinpaiByPinzhong(String mmPinzhongOne){
        return ddMapper.findPinpaiByPinzhong(mmPinzhongOne);
    }
    public List<Map<String, Object>> findPinpaiResultByPinzhong(String ppxiangmuId,String ppuserId,String mmPinzhongOne){
        return ddMapper.findPinpaiResultByPinzhong(ppxiangmuId,ppuserId,mmPinzhongOne);
    }
    public List<Map<String, Object>> findPinpaiFenlei(String mmPinzhongOne){
        return ddMapper.findPinpaiFenlei(mmPinzhongOne);
    }
    public List<Map<String, Object>> findXinghaoByPinpai(String ppPinzhong,String ppPinpai){
        return ddMapper.findXinghaoByPinpai(ppPinzhong,ppPinpai);
    }
    public List<Map<String, Object>> findXinghaoJieguoByPinpai(String ppPinzhong,String ppPinpai,String ppxiangmuId, String ppuserId){
        return ddMapper.findXinghaoJieguoByPinpai(ppPinzhong,ppPinpai,ppxiangmuId,ppuserId);
    }

    public List<Map<String, Object>> findHaocaiyinjinlist(String ppxiangmuId,int ppPageIndex, int ppPageSize){
        int mmStartIndex = (ppPageIndex - 1) * ppPageSize;
        return ddMapper.selectByXiangmuId(ppxiangmuId,mmStartIndex,ppPageSize);
    }

   /* public List<Map<String, Object>> findBiaojuelist(String mmxiangmuId, String mmuserId,int ppPageIndex, int ppPageSize){

        return ddMapper.findBiaojuelist(mmxiangmuId,mmuserId,ppPageIndex,ppPageSize);
    }*/

    public Integer getHaocaiyinjinlist(String ppxiangmuId,int ppPageIndex, int ppPageSize) {
        Object mmCount = ddMapper.getHaocaiyinjinlist(ppxiangmuId,ppPageIndex,ppPageSize);
        return mmCount == null ? 0 : Integer.parseInt(mmCount.toString());
    }

    public Integer getVoteCount(String ppxiangmuId){
        List<Map<String, Object>> list=ddMapper.findPinzhongAndPinpaiByXiangmuId(ppxiangmuId);
        return list == null ? 0 : list.size();
    }

    public boolean deleteByxiangmuId(String xiangmuId){
        HaocaiyinjinExample mmExample=new HaocaiyinjinExample();
        HaocaiyinjinExample.Criteria criteria=mmExample.createCriteria();
        criteria.andXiangmuidEqualTo(xiangmuId);
        return  ddMapper.deleteByExample(mmExample)>=0;
    }

    public boolean add (Haocaiyinjin ddHaocaiyinjin){
        return ddMapper.insert(ddHaocaiyinjin)==1;
    }

    public boolean isexistByxiangmuId(String xiangmuId){
       HaocaiyinjinExample mmExample=new HaocaiyinjinExample();
       HaocaiyinjinExample.Criteria criteria=mmExample.createCriteria();
       criteria.andXiangmuidEqualTo(xiangmuId);
       return  ddMapper.selectByExample(mmExample).size()>0;
    }

      public List<Map<String, Object>> findBiaojuelist(String mmxiangmuId, String mmuserId){

        return ddMapper.findBiaojuelist(mmxiangmuId,mmuserId);
    }

    public Integer getCountByXiangmuId(String mmxiangmuId){
        HaocaiyinjinExample mmExample=new HaocaiyinjinExample();
        HaocaiyinjinExample.Criteria criteria=mmExample.createCriteria();
        criteria.andXiangmuidEqualTo(mmxiangmuId);
        return ddMapper.countByExample(mmExample);
    }

    public List<Haocaiyinjin> findAllByXiangmuId(String mmxiangmuId) {
        HaocaiyinjinExample mmExample = new HaocaiyinjinExample();
        HaocaiyinjinExample.Criteria criteria = mmExample.createCriteria();
        criteria.andXiangmuidEqualTo(mmxiangmuId);
        return ddMapper.selectByExample(mmExample);
    }

    public List<Map<String, Object>> findPinguiResult(String ppxiangmuId){
        return ddMapper.findPinguiResult(ppxiangmuId);
    }


}
